﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CreateContinuousMFGFromCurve.CApCMCCreateContinuousMFGFromCurveTCLogic
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using EngineeringInternalExtension;
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.DataTypes;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands.CreateContinuousMFGFromCurve;

internal class CApCMCCreateContinuousMFGFromCurveTCLogic : CApCMCCreateContinuousMFGFromCurveLogic
{
  private TxObjEditBoxCtrl _mfgContainerCtrl;
  private TxObjEditBoxCtrl _operationCtrl;
  private const string _CONTINUOUS_MFG_METADATA_TYPE_TC = "ArcWeldRevision";

  public CApCMCCreateContinuousMFGFromCurveTCLogic(
    TxObjGridCtrl mfgList,
    TxObjEditBoxCtrl assignToPart,
    TxObjEditBoxCtrl mfgContainer,
    TxObjEditBoxCtrl operationCtrl,
    ComboBox mfgType,
    Button okButton)
    : base(mfgList, assignToPart, mfgType, okButton, "ArcWeldRevision")
  {
    this._mfgContainerCtrl = mfgContainer;
    this._operationCtrl = operationCtrl;
  }

  public override List<TxSeamMfgFeature> CreateMFGs(string mfgTypeName)
  {
    this.ModifyMfgData = (Func<ITxSeamMfgFeatureCreationData, ITxSeamMfgFeatureCreationData>) (data =>
    {
      ITxTcSeamMfgFeatureCreationData featureCreationData = (ITxTcSeamMfgFeatureCreationData) null;
      ITxTcExposedMfgFeatureData exposedMfgFeatureData = (ITxTcExposedMfgFeatureData) null;
      if (this._mfgContainerCtrl.Enabled && this._mfgContainerCtrl.Object != null)
        exposedMfgFeatureData = TxMfgCreationDataFactory.CreateTcExposedMfgData(this._mfgContainerCtrl.Object as TxCompoundPart);
      if (this._operationCtrl.Object != null)
      {
        ITxMfgFeaturesContainingOperation containingOperation = this._operationCtrl.Object as ITxMfgFeaturesContainingOperation;
        featureCreationData = exposedMfgFeatureData == null ? TxMfgCreationDataFactory.CreateTcSeamMfgFeatureCreationData(data, containingOperation) : (ITxTcSeamMfgFeatureCreationData) TxMfgCreationDataFactory.CreateTcExposedSeamMfgFeatureCreationData(data, containingOperation, exposedMfgFeatureData);
      }
      return (ITxSeamMfgFeatureCreationData) featureCreationData ?? data;
    });
    return base.CreateMFGs(mfgTypeName);
  }

  public void UpdateMfgToRevision(List<TxSeamMfgFeature> listSeamMfgs)
  {
    foreach (TxSeamMfgFeature listSeamMfg in listSeamMfgs)
      new TxSeamMfgFeatureEx(listSeamMfg)?.CopyScopeToRevision();
  }

  public void EnableOrDisableAcceptButton()
  {
    bool flag = this._mfgList.Count > 0 && (this._assignToPart.Object != null || !(((Control) this._assignToPart).Text != string.Empty));
    if (flag)
    {
      try
      {
        for (int index = 0; index < this._mfgList.Count & flag; ++index)
        {
          if (string.IsNullOrEmpty(this._mfgList.GetTextValue(index, 0)))
            flag = false;
        }
      }
      catch
      {
        flag = false;
      }
    }
    if (flag && ((!this._mfgContainerCtrl.Enabled || this._mfgContainerCtrl.Object == null) && this._mfgContainerCtrl.Enabled || this._operationCtrl.Object == null))
      flag = false;
    this._okButton.Enabled = flag;
  }
}
